#include <iostream>
#include <cstdio>
using namespace std;
int aa[100000];
int n;
void HeapAdjust(int a[],int ps,int len)
{
    int i;
    for(i=ps*2+1;i<len;i=i*2+1)
    {
        if(i+1<len&&a[i]<a[i+1])++i;
        if(a[(i-1)/2]>a[i])break;
        else swap(a[(i-1)/2],a[i]);
    }
}
void BuildHeap(int a[],int len)
{
    int i;
    for(i=len/2-1;i>=0;i--)
    {
        HeapAdjust(a,i,len);
    }
}
void print()
{
    for(int i=0;i<n-1;i++)
    {
        cout<<aa[i]<<" ";
    }
    cout<<aa[n-1]<<endl;
}
void HeapSort(int a[],int len)
{
    int i;
    BuildHeap(a,len);
    print();
    for(i=len-1;i>0;i--)
    {
        swap(a[0],a[i]);
        HeapAdjust(a,0,i);
        print();
    }
}
int main()
{
    int i;
    while(cin>>n)
    {
        for(i=0;i<n;i++)
            scanf("%d",aa+i);
        HeapSort(aa,n);
    }
    return 0;
}
